package com.aring.deals.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import com.aring.deals.service.TimeManager;

public class ContextLister implements ServletContextListener{

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		ServletContext context = sce.getServletContext();
	    TimeManager manager = (TimeManager) context.getAttribute("TimeManager");
        manager.stop();
	}

	@Override
	public void contextInitialized(ServletContextEvent sce) {
	     TimeManager manager = new TimeManager();
	     manager.start();
	     ServletContext context = sce.getServletContext();
	     context.setAttribute("TimeManager", manager);   
	}

}
